#!/usr/bin/env python
# encoding: utf-8
import os


class recorder():
	filename = ''
	error_file = ''
	
	def __init__(self):
		self.filename = os.path.join('.','history.txt')
		self.error_file = os.path.join('.','error.txt')
	
	def hasTrack(self,album,artist=""):
		history = open(self.filename)
		for line in history.readlines():
			line = line.decode('utf-8')
			if album+"-"+artist in line:
				#print line+"alread exists"
				return True
		
		return False
		pass
		
	def writeTrack(self,album,artist=""):
		info = album+"-"+artist+"\n"
		#print info
		info = info.encode('utf-8')
		
		open(self.filename,'a').write(info)
		pass
	
	def writeError(self,album,artist):
		info = "NO FOUND"+album+"-"+artist+"\n"
		
		info = info.encode('utf-8')
		
		open(self.error_file,'a').write(info)
		pass
	def clear(self):
		open(self.filename,'w+').write('\n')
		open(self.error_file,'w+').write('\n')

def main():
	r = recorder()
	r.writeTrack("aaa","bbb")
	r.hasTrack("aaa","bbb")
	r.clear()

if __name__ == "__main__":
	main()